package com.lsy.weizhi2.popupwindow;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.PopupWindow;

import com.lsy.weizhi2.R;
import com.lsy.weizhi2.mybase.BaseApp;
import com.lsy.weizhi2.myutils.FenXiangPopupCall;
import com.zhy.autolayout.utils.AutoUtils;

/**
 * Created by 嗨哟 on 2017/3/18.
 */
public class FenXiangPopup implements View.OnClickListener{
    private PopupWindow fenxiangpopup;
    private FenXiangPopupCall fenXiangPopupCall;
    private ImageView qq_image,weixin_image,weibo_image,qq_image2,weixin_image2,weibo_image2;
    public void init(Context context,View parent){
        View view=View.inflate(context, R.layout.fenxiangpopup,null);
        AutoUtils.autoSize(view);
        qq_image= (ImageView) view.findViewById(R.id.qq_image);
        weixin_image= (ImageView) view.findViewById(R.id.weixin_image);
        weibo_image= (ImageView) view.findViewById(R.id.weibo_image);
        qq_image2= (ImageView) view.findViewById(R.id.qq_image2);
        weixin_image2= (ImageView) view.findViewById(R.id.weixin_image2);
        weibo_image2= (ImageView) view.findViewById(R.id.weibo_image2);
        qq_image.setOnClickListener(this);
        weixin_image.setOnClickListener(this);
        weibo_image.setOnClickListener(this);
        qq_image2.setOnClickListener(this);
        weixin_image2.setOnClickListener(this);
        weibo_image2.setOnClickListener(this);
        fenxiangpopup=new PopupWindow(context);
        fenxiangpopup.setContentView(view);
        fenxiangpopup.setWidth(BaseApp.SCREEN_WIDTH);
        fenxiangpopup.setHeight(BaseApp.REAL_HEIGHT*540/1334);
        ColorDrawable dw = new ColorDrawable(0xffffffff);
        fenxiangpopup.setBackgroundDrawable(dw);
        fenxiangpopup.setFocusable(true);
        fenxiangpopup.showAtLocation(parent, Gravity.BOTTOM,0,0);
        fenxiangpopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                fenXiangPopupCall.dismissListener();
            }
        });
    }

    public void setFenXiangPopupCall(FenXiangPopupCall fenXiangPopupCall){
        this.fenXiangPopupCall=fenXiangPopupCall;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.qq_image:
                fenXiangPopupCall.onClick(view,FenXiangPopupCall.QQ);
                break;
            case R.id.qq_image2:
                fenXiangPopupCall.onClick(view,FenXiangPopupCall.QQ2);
                break;
            case R.id.weixin_image:
                fenXiangPopupCall.onClick(view,FenXiangPopupCall.WEIXIN);
                break;
            case R.id.weixin_image2:
                fenXiangPopupCall.onClick(view,FenXiangPopupCall.WEIXIN2);
                break;
            case R.id.weibo_image:
                fenXiangPopupCall.onClick(view,FenXiangPopupCall.WEIBO);
                break;
            case R.id.weibo_image2:
                fenXiangPopupCall.onClick(view,FenXiangPopupCall.WEIBO2);
                break;
        }
    }
}
